<?php
    // +----------------------------------------------------------------------
    // | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ] 
    // +----------------------------------------------------------------------
    // | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
    // +----------------------------------------------------------------------
    // | SiteUrl: http://www.luckyhhy.cn
    // +----------------------------------------------------------------------
    // | Author: LuckyHhy <jackhhy520@qq.com>
    // +----------------------------------------------------------------------
    // | Date: 2020/3/25-10:31
    // +----------------------------------------------------------------------
    // | Description: 职级
    // +----------------------------------------------------------------------


    namespace app\admin\controller\company;


    use app\admin\controller\AdminBase;
    use app\admin\model\Positions;
    use app\admin\validate\PositionValidate;

    /**
     * Class Position
     * @package app\admin\controller\company
     */
    class Position extends AdminBase
    {
        /**
         * @throws \think\Exception
         * @throws \think\db\exception\DataNotFoundException
         * @throws \think\db\exception\ModelNotFoundException
         * @throws \think\exception\DbException
         * @throws \think\exception\PDOException
         * @author: LuckyHhy <jackhhy520@qq.com>
         * @date: 2020/3/25
         * @name: initialize
         * @describe:
         */
        public function initialize()
        {
            parent::initialize(); // TODO: Change the autogenerated stub

            $this->model=app()->model("Positions");

            $this->del="职级";
        }



        /**
         * @param Positions $positions
         * @return mixed
         * @throws \think\Exception
         * @throws \think\db\exception\DataNotFoundException
         * @throws \think\db\exception\ModelNotFoundException
         * @throws \think\exception\DbException
         * @throws \think\exception\PDOException
         * @author: LuckyHhy <jackhhy520@qq.com>
         * @date: 2020/3/25
         * @name: addPosition
         * @describe:
         */
        public function addPosition(Positions $positions){
            if (IS_POST){
                $data = $this->request->post();
                $validate=new PositionValidate();

                if (!$validate->check($data)){
                    $this->error($validate->getError());
                }

                if (isset($data['id'])){
                    addLog("职级操作","职级岗位：".$data['pname']);
                }else{
                    $k=$positions->where("pname",$data['pname'])->find();

                    if ($k){
                        $this->error("当前职级已有");
                    }

                    addLog("职级操作","职级岗位：".$data['pname']);
                }
                return $this->model->addAndEdit($data);
            }

            $this->assign("info",[]);

            return $this->fetch();
        }



        /**
         * @return mixed
         * @author: LuckyHhy <jackhhy520@qq.com>
         * @date: 2020/3/25
         * @name: editStation
         * @describe:
         */
        public function editPosition(){

            $d_id = $this->request->param("id/d");//父id

            $info=$this->model->getOne($d_id);

            if (!$info){
                $this->assign('msg','当前id:'.$d_id.'错误');
                $this->fetch("public/404");
            }

            $this->assign("info",$info);

            return $this->fetch("add_position");
        }




    }